package com.lc.user.express.httpserver;

import com.lc.user.express.model.CouponModel;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/30.我的优惠券
 */
@HttpInlet(Net.GET_COUPON)
public class GetMyCoupon extends ZJDBAsyGet<GetMyCoupon.Info>{
      public  String userid;//用户id
      public int page;//当前页

    public GetMyCoupon(String userid, int page,AsyCallBack listener) {
        super(listener);
        this.userid = userid;
        this.page=page;
    }

    @Override
    protected Info parser(JSONObject object) {
        if(object.optInt("message")==1){
            Info info =new Info();
            info.ispage=object.optInt("ispage");
            info.nextpage=object.optInt("nextpage");
            JSONArray array = object.optJSONArray("list");
            if (array!=null){

                for (int i=0; i<array.length(); i++ ){
                    JSONObject object1=array.optJSONObject(i);
                    CouponModel model = new CouponModel();
                    model.setStartTime(object1.optString("startime"));
                    model.setEndTime(object1.optString("endtime"));
                    model.setAccount(object1.optString("account"));
                    info.list.add(model);
                }
                return info;
            }
        }
        return null;
    }

    public static class Info{
        public List<CouponModel> list = new ArrayList<>();
        public int  nextpage;//分页
        public  int ispage;//是否有下一页

    }

}
